use libc::c_float;

#[repr(C)]
struct FfiVector {
    data: *mut c_float,
    len: i32,
}

extern "C" {
    fn vector_add_wrapper(x: *const FfiVector, y: *const FfiVector, z: *mut FfiVector);
}

fn main() {
    // 使用Vec<f32>而不是Vec<i32>
    let x_data: Vec<f32> = vec![1.0, 2.0, 3.0, 4.0];
    let y_data: Vec<f32> = vec![5.0, 6.0, 7.0, 8.0];
    let mut z_data: Vec<f32> = vec![0.0; x_data.len()];

    // 确保数据在整个操作期间保持有效
    let x = FfiVector {
        data: x_data.as_ptr() as *mut c_float,
        len: x_data.len() as i32,
    };
    let y = FfiVector {
        data: y_data.as_ptr() as *mut c_float,
        len: y_data.len() as i32,
    };
    let mut z = FfiVector {
        data: z_data.as_mut_ptr() as *mut c_float,
        len: z_data.len() as i32,
    };

    // 调用 CUDA 函数
    unsafe {
        vector_add_wrapper(&x, &y, &mut z);
    }

    // 打印结果
    println!("Result: {:?}", z_data);
}
